<template>
    <div class="fromBox">
        <el-form ref="ruleForm" :model="ruleForm" :rules="rules">
            <el-form-item prop="title">
                <el-input v-model="ruleForm.title" size="small" placeholder="项目名称"></el-input>
            </el-form-item>
            <el-form-item prop="description">
                <el-input v-model="ruleForm.description" rows="12"  placeholder="项目简介" resize="none" type="textarea" size="small">
                </el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>
<script>
    export default {
        props: ['closeEvent', 'projectData'],
        data() {
            return {
                project: {},
                ruleForm: {
                    title: '',
                    description: '',
                },
                rules: {
                    title: { required: true, message: '请输入项目名', trigger: 'change' },
                }
            }
        },
        mounted() {
            this.project = JSON.parse(JSON.stringify(this.projectData));
            this.ruleForm.title = this.project.title;
            this.ruleForm.description = this.project.description;
        },
        methods: {
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        if (this.project.projectId) {
                            window.action.updateLoaclProject(this.project.projectId, this.ruleForm).then((res) => {
                                if (res) {
                                    this.closeEvent();
                                };
                            });
                        } else {
                            window.action.creatLoaclProject(this.ruleForm).then((res) => {
                                if (res) {
                                    this.closeEvent();
                                };
                            });
                        };
                    } else {
                        return false;
                    }
                });
            }
        },
    }
</script>

<style scoped>
    .fromBox { padding: 0 40px;}


</style>